package com.whw.fy.controller;

import com.alibaba.fastjson.JSON;
import com.whw.fy.entity.Message;
import com.whw.fy.entity.Parent;
import com.whw.fy.entity.Student;
import com.whw.fy.entity.TrainingInstitutionRecords;
import com.whw.fy.service.StudentService;
import com.whw.fy.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "学生模块")
@RestController
@RequestMapping("/api/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    @ApiOperation(value = "新增学生")
    @PostMapping("/one")
    public Message insert(Student student) throws ParseException {
        student.setStudentJoinCenter(new Date());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (student.getStudentBirthtoString()!=null)
        student.setStudentBirth(simpleDateFormat.parse(student.getStudentBirthtoString()));
        return studentService.insertSelective(student);
    }

    @ApiOperation(value = "家长页面新增学生")
    @PostMapping("/parent/one")
    public Message parentinsert(Student student) throws ParseException {
        student.setStudentJoinCenter(new Date());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (student.getStudentBirthtoString()!=null)
            student.setStudentBirth(simpleDateFormat.parse(student.getStudentBirthtoString()));
        return studentService.parentinsert(student);
    }

    @ApiOperation(value = "根据学生id删除学生")
    @DeleteMapping("/")
    public Message delete(Integer parentId) {
        return studentService.deleteByPrimaryKey(parentId);
    }

    @ApiOperation(value = "根据学生id修改学生信息")
    @PutMapping("/")
    public Message update(Student student) throws ParseException {
        return studentService.updateByPrimaryKeySelective(student);
    }

    @ApiOperation(value = "根据学生id查询学生信息")
    @GetMapping("/id")
    public Message selectById(int id){
        return studentService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "查询所有学生信息")
    @GetMapping("/all")
    public Message selectAll(){
        return studentService.selectAll();
    }

    @ApiOperation(value = "查询所有学生姓名<地址>")
    @GetMapping("/selectStudentNameAndAdd")
    public Message selectStudentNameAndAdd(){
        return studentService.selectStudentNameAndAdd();
    }

    @ApiOperation(value = "根据家长id查询学生姓名<地址>")
    @GetMapping("/selectStudentNameAndAddByParentId")
    public Message selectStudentNameAndAddByParentId(int parentId){
        return studentService.selectStudentNameAndAddByParentId(parentId);
    };

    @ApiOperation(value = "根据班级id查询学生姓名<地址>")
    @GetMapping("/selectStudentNameAndAddByClassId")
    public Message selectStudentNameAndAddByClassId(int ClassId){
        return studentService.selectStudentNameAndAddByClassId(ClassId);
    };

    @ApiOperation(value = "根据学生id获得购买课程记录和待办事件")
    @GetMapping("/selectPurchaseAndEmergencyByStudentId")
    public Message selectPurchaseAndEmergencyByStudentId(int studentId){
        return studentService.selectPurchaseAndEmergencyByStudentId(studentId);
    }

    @ApiOperation(value = "根据学生id查询学生上课记录")
    @GetMapping("/selectAllByStudentId")
    public Message selectCommentByStudentId(int studentId){
        return studentService.selectCommentByStudentId(studentId);
    }

    @ApiOperation(value = "新的学生添加接口")
    @PostMapping("/new")
    public Message newAdd(Student student,String list){
        //student.setStudentJoinCenter(new Date());
        List<TrainingInstitutionRecords> trainingInstitutionRecordsList = JSON.parseArray(list,TrainingInstitutionRecords.class);
        return studentService.newAdd(student,trainingInstitutionRecordsList);
    }

    @ApiOperation(value = "新的学生修改接口")
    @PostMapping("/newupdate")
    public Message newUpdate(Student student,String list){

        return studentService.newUpdate(student,list);
    }

    @ApiOperation(value = "医疗主管录入学生临床信息")
    @PostMapping("/insertStudentTreat")
    public Message insertStudentTreat(Student student){
        return studentService.insertStudentTreat(student);
    }

    @ApiOperation(value = "根据授课老师id查询旗下所有学生")
    @GetMapping("/all/TeacherIdJurisdictionEight")
    public Message selectallByTeacherIdJurisdictionEight(int staffId){
        return studentService.selectallByTeacherIdJurisdictionEight(staffId);
    }

    @ApiOperation(value = "根据医疗主管id查询旗下所有学生")
    @GetMapping("/all/MedicalDirectorIdJurisdictionZero")
    public Message selectallByMedicalDirectorIdJurisdictionZero(int staffId){
        return studentService.selectallByMedicalDirectorIdJurisdictionZero(staffId);
    }

    @ApiOperation(value = "根据主责老师id查询旗下所有学生")
    @GetMapping("/all/principalTeacherJurisdictionSeven")
    public Message selectallByprincipalTeacherJurisdictionSeven(int staffId){
        return studentService.selectallByprincipalTeacherJurisdictionSeven(staffId);
    }

    @ApiOperation(value = "根据教学主管id查询旗下所有学生")
    @GetMapping("/all/TeachingDirectorJurisdictionSix")
    public Message selectallByTeachingDirectorJurisdictionSix(int staffId){
        return studentService.selectallByTeachingDirectorJurisdictionSix(staffId);
    }
}
